﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Windows;

namespace PersonHealth
{

    public class ScreenKeyboard
    {
        private const uint SWP_NOSIZE = 0x0001;
        private const uint SWP_NOMOVE = 0x0002;
        private const uint SWP_NOZORDER = 0x0004;
        private const uint SWP_NOREDRAW = 0x0008;
        private const uint SWP_NOACTIVATE = 0x0010;
        private const uint SWP_FRAMECHANGED = 0x0020;
        private const uint SWP_SHOWWINDOW = 0x0040;
        private const uint SWP_HIDEWINDOW = 0x0080;
        private const uint SWP_NOCOPYBITS = 0x0100;
        private const uint SWP_NOOWNERZORDER = 0x0200;
        private const uint SWP_NOSENDCHANGING = 0x0400;

        [DllImport("user32.dll")]
        static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,
                                        int Y, int cx, int cy, uint uFlags);

        [DllImport("user32.dll")]
        static extern bool SetForegroundWindow(IntPtr hWnd);
        public static void ShowScreenKeyboard()
        {
            if (System.IO.File.Exists(Environment.SystemDirectory + "\\osk.exe"))
            {
                Process process = new Process();
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError = true;
                process.StartInfo.CreateNoWindow = true;
                process.StartInfo.FileName = "osk.exe";
                process.StartInfo.Arguments = "";
                process.Start();
                process.WaitForInputIdle();
                System.Windows.Interop.WindowInteropHelper winHelper = new System.Windows.Interop.WindowInteropHelper(Application.Current.MainWindow);
                IntPtr mainWindowHandle = winHelper.Handle;
                SetWindowPos(process.MainWindowHandle,
                mainWindowHandle,
                0,
                0,
                100,
                200,
                SWP_SHOWWINDOW | SWP_NOZORDER);


                SetForegroundWindow(process.MainWindowHandle);
            }

        }
    }
}
